//
//  JSMStrategyContinentAllCollectionViewCell.m
//  TakeYouTourTogether
//
//  Created by king on 15/12/6.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMStrategyContinentAllCollectionViewCell.h"

@implementation JSMStrategyContinentAllCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createStrategyContinentAllCollectionViewCell];
    }
    return self;
}

- (void)createStrategyContinentAllCollectionViewCell {
    self.myImageView = [[BaseImageView alloc] init];
    self.myImageView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.myImageView];
    
    self.myLabel = [[BaseLabel alloc] init];
    self.myLabel.backgroundColor = [UIColor clearColor];
    self.myLabel.textColor = [UIColor whiteColor];
    self.myLabel.font = [UIFont boldSystemFontOfSize:20];
    self.myLabel.highlightedTextColor = [UIColor whiteColor];
    [self.contentView addSubview:self.myLabel];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:21], NSFontAttributeName, nil];
    CGRect rect = [self.myLabel.text boundingRectWithSize:CGSizeMake(TABLEVIEWCELL_WIDTH, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    [self.myImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(10, 0, 0, 0));
    }];
    self.myLabel.frame = CGRectMake(0, 0, rect.size.width, TABLEVIEWCELL_HEIGHT-10);
    self.myLabel.center = self.contentView.center;
}

- (void)setTempModel:(JSMStrategyContinentAllModel *)tempModel {
    if (_tempModel != tempModel) {
        _tempModel = tempModel;
    }
    [self.myImageView sd_setImageWithURL:[NSURL URLWithString:tempModel.cover] placeholderImage:[UIImage imageNamed:PLACE_HOLDER_IMAGE]];
    self.myLabel.text = tempModel.name;
}

@end
